using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HS_Cloth : MonoBehaviour
{
    #region Variables
    Dictionary<string, Transform> m_clothesDic = new Dictionary<string, Transform>();
    #endregion

    public void LoadClothesBoneDic()
    {
        m_clothesDic.Clear();

        Transform[] tmpBones = transform.GetComponentsInChildren<Transform>();
        foreach (Transform bone in tmpBones)
        {
            if (!m_clothesDic.ContainsKey(bone.name))
                m_clothesDic.Add(bone.name, bone);
        }
    }

    public Transform GetClothesBone(string boneName, bool fuzzy = false)
    {
        if (!fuzzy)
        {
            try
            {
                return m_clothesDic[boneName];
            }
            catch (System.Exception e)
            {
                Debug.LogWarning("No Valid Bone Detected! Error : " + e);
                return null;
            }
        }
        else
        {
            try
            {
                foreach (var name in m_clothesDic.Keys)
                {
                    if (name.Contains(boneName))
                        return m_clothesDic[name];
                }

                return m_clothesDic[boneName];
            }
            catch (System.Exception e)
            {
                Debug.LogWarning("No Valid Bone Detected! Error : " + e);
                return null;
            }
        }
    }
}
